/*******************************************************************************
 * Copyright (c) 2008 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.tabbedproperties.section;

import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Reception;
import org.eclipse.uml2.uml.Signal;

import com.cea.papyrus.core.filters.TypeFilter;
import com.cea.papyrus.core.tabbedproperties.AbstractSelectionElementSection;

/**
 * This class is used to display section about the signal associated to a Reception
 */
public class ReceptionSection extends AbstractSelectionElementSection {

	/**
	 * Creates a new ReceptionSection.
	 */
	public ReceptionSection() {
		super("Signal: ", new TypeFilter());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public NamedElement getReferencedElementToDisplay() {
		if(getElement() instanceof Reception) {
			Signal signal = ((Reception)getElement()).getSignal();
			if(signal!=null) {
				return signal;
			}
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void removeReferencedElement() {
		if(getElement() instanceof Reception) {
			((Reception)getElement()).setSignal(null);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setReferencedElement(NamedElement element) {
		if (element instanceof Signal){
			Signal signal = (Signal)element;
			if(getElement() instanceof Reception) {
				((Reception)getElement()).setSignal(signal);
			}
		}
	}
}